package org.team4.service.meta;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.team4.constants.SQLConstant;
import org.team4.dao.DAOFactory;
import org.team4.dao.meta.OperateDAO;
import org.team4.domain.VmetaOperate;
import org.team4.exception.CRUDException;
import org.team4.service.IService;
import org.team4.util.Validate;


@Service
public class OperateService implements IService {

    private OperateDAO operateDAO;

    @Autowired
    public void setSessionFactory(SessionFactory sessionFactory) {
        operateDAO = (OperateDAO) DAOFactory.getDAO(sessionFactory, OperateDAO.class);
    }

    /**
     * 查找模块操作
     * 
     * @param superId
     * @return
     * @throws CRUDException
     */
    public List<VmetaOperate> listOperateByModuleId(String superId) throws CRUDException {
        if (Validate.notNull(superId))
            return operateDAO.find(SQLConstant.OPERATE_BY_MODULE_HQL, superId);
        else
            return null;
    }

    /**
     * 查找可用操作
     * 
     * @param moduleId
     * @return
     * @throws CRUDException
     */
    public List<VmetaOperate> listOperateByModuleIdAndVisible(String moduleId) throws CRUDException {
        if (Validate.notNull(moduleId))
            return operateDAO.find(SQLConstant.OPERATE_BY_MODULE_VISIBLE_HQL, moduleId);
        else
            return null;
    }

    /**
     * 获得操作
     * 
     * @param id
     * @return
     * @throws CRUDException
     */
    public VmetaOperate findOperateById(String id) throws CRUDException {
        return operateDAO.get(id);
    }

    /**
     * 删除操作
     * 
     * @param idList
     * @throws CRUDException
     */
    public void deleteOperates(List<String> idList) throws CRUDException {
        operateDAO.deleteByIdList(idList);
    }
}